<?php
/**
 * [DB模型]
 * 
 * @version $Id: Classes.php 647 2013-01-23 06:39:11Z linsir123 $
 */
class dbClasses extends ActiveRecord 
{
	/**
	 * @var 数据库表名
	 */
	public $table = 'classes2';
	
	/**
	 * @var [分表]对应的创建分表的SQL
	 */
	public $sqlPartition = "
CREATE TABLE IF NOT EXISTS `%s` (
  `id` int(11) NOT NULL auto_increment COMMENT 'ID',
  `class_id` int(11) NOT NULL COMMENT '分类ID',
  `parent_id` int(11) NOT NULL COMMENT '分类父ID',
  `pinyin` varchar(255) NOT NULL COMMENT '拼音',
  `title` varchar(255) NOT NULL COMMENT '内容',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `class_id` (`class_id`),
  KEY `parent_id_pinyin` (`parent_id`, `pinyin`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='分类表' AUTO_INCREMENT=1 ;
	";
	
	/**
	 * 保存
	 */
	public function save($parentId, $pinyin, $classId, $title)
	{
		return $this->insertDuplicate(array(
			'class_id' => $classId, 
			'parent_id' => $parentId, 
			'pinyin' => $pinyin, 
			'title' => $title, 
		), array(), array('parent_id', 'pinyin', 'title'));
	}
}
